﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FCS.Test
{
    /// <summary>
    /// Summary description for FoldsTests
    /// </summary>
    [TestClass]
    public class FoldsTests : Functional
    {
        public FoldsTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void FoldlTest()
        {
            Assert.AreEqual(10, Foldl((a, b) => a + b, 0, IntList(1, 4)));

            Assert.AreEqual(64, Foldl((a, b) => (int)Math.Pow(a, b), 2, IntList(2, 3)));
            Assert.AreEqual(4096, Foldl((a, b) => (int)Math.Pow(a, b), 2, IntList(3, 4)));

            Assert.AreEqual(2, Foldl((a, b) => (int)Math.Pow(a, b), 2, IntList(2, -2)));
            Assert.AreEqual(4, Foldl((a, b) => (int)Math.Pow(a, b), 2, IntList(2, 2)));
        }

        [TestMethod]
        public void FoldrTest()
        {
            Assert.AreEqual(10, Foldr((a, b) => a + b, 0, IntList(1, 4)));

            Assert.AreEqual(512, Foldr((a, b) => (int)Math.Pow(a, b), 2, IntList(2, 3)));
            Assert.AreEqual(43046721, Foldr((a, b) => (int)Math.Pow(a, b), 2, IntList(3, 4)));

            Assert.AreEqual(2, Foldr((a, b) => (int)Math.Pow(a, b), 2, IntList(2, -2)));
            Assert.AreEqual(4, Foldr((a, b) => (int)Math.Pow(a, b), 2, IntList(2, 2)));
        }
    }
}
